package org.xiaoyu.rpc.loadbalance;

import org.xiaoyu.rpc.Loadbalancer;
import org.xiaoyu.rpc.common.url.URL;
import org.xiaoyu.rpc.remoting.packet.Invocation;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created By Have
 * 2021/7/14 17:14
 */
public class FairLoadbalancer implements Loadbalancer {
    private static AtomicInteger atomicInteger = new AtomicInteger(0);

    @Override
    public URL loadBalance(List<URL> urls, Invocation invocation) {
        int andIncrement = atomicInteger.getAndIncrement();
        return urls.get(andIncrement % urls.size());
    }
}
